package com.lss.study.algorithm.niuke.T8;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * 功能描述：
 *
 * @Date: 2022/2/19 18:21
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            String[] arr = scanner.nextLine().split(" ");
            if (!map.containsKey(Integer.parseInt(arr[0]))) {
                map.put(Integer.parseInt(arr[0]), Integer.parseInt(arr[1]));
            } else {
                map.put(Integer.parseInt(arr[0]), map.get(Integer.parseInt(arr[0])) + Integer.parseInt(arr[1]));
            }
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}
